package com.duoduo.demo.springnoxml.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.duoduo.demo.springnoxml.dao.HelpKeywordDao;
import com.duoduo.demo.springnoxml.model.HelpKeyword;
import com.duoduo.demo.springnoxml.vo.HelpKeywordVO;

@Service
public class HelpKeywordService {

	@Autowired
	private HelpKeywordDao helpKeywordDao;

	public List<HelpKeywordVO> listAll() {
		return fromEntityList(helpKeywordDao.listAll());
	}

	public List<HelpKeywordVO> listByTopic(int topicId) {
		return fromEntityList(helpKeywordDao.listByTopic(topicId));
	}

	private List<HelpKeywordVO> fromEntityList(List<HelpKeyword> entityList) {
		List<HelpKeywordVO> voList = new ArrayList<HelpKeywordVO>(0);
		if (CollectionUtils.isEmpty(entityList)) {
			return voList;
		}

		for (HelpKeyword entity : entityList) {
			voList.add(HelpKeywordVO.fromEntity(entity));
		}
		return voList;
	}
}
